RUBY-3901 Client backpressure with baseBackoffMS - #3103
Merged
comandeo-mongo merged 7 commits intoAug 19, 2026
Conversation
comandeo-mongo
marked this pull request as ready for review
August 18, 2026 12:18
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Ruby MongoDB driver’s client backpressure implementation and related specs to match updated client-backpressure behavior (new exponential backoff schedule, support for server-supplied baseBackoffMS, and updated handshake metadata).
Changes:
- Adjust exponential backoff calculations (including
with_transactionand backpressure retry loops) and update expectations in specs. - Add support for server-supplied
baseBackoffMSand plumb the triggering error into backoff computation. - Ensure
Client#withrebuilds the retry policy whenmaxAdaptiveRetrieschanges, and update handshake metadata backpressure value.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/mongo/session/with_transaction_overload_spec.rb | Updates expected overload backoff sleep duration in with_transaction specs. |
| spec/mongo/session_transaction_prose_spec.rb | Updates expected summed backoff time to match new retry backoff schedule. |
| spec/mongo/server/app_metadata_backpressure_spec.rb | Updates handshake backpressure expectation (but needs matcher/description fix). |
| spec/mongo/retryable/client_backpressure_prose_spec.rb | Reworks prose tests to run against a real cluster using failpoints; updates timing logic. |
| spec/mongo/retryable/client_backpressure_no_backoff_prose_spec.rb | Makes timing-based “no extra backoff” test deterministic by pinning jitter and recalculating bounds. |
| spec/mongo/retryable/backpressure_spec.rb | Updates unit expectations for new exponential series and adds coverage for baseBackoffMS override. |
| spec/mongo/retryable/backpressure_options_spec.rb | Adds coverage for Client#with correctly rebuilding retry policy for maxAdaptiveRetries. |
| lib/mongo/session.rb | Passes error into overload backoff calculation and adjusts with_transaction retry backoff exponent. |
| lib/mongo/server/app_metadata.rb | Changes handshake client_document[:backpressure] value to '2'. |
| lib/mongo/retryable/write_worker.rb | Passes the last error into overload backoff computation for writes. |
| lib/mongo/retryable/retry_policy.rb | Extends backoff_delay API to accept err: and forwards it to Backpressure. |
| lib/mongo/retryable/read_worker.rb | Passes the last error into overload backoff computation for reads. |
| lib/mongo/retryable/backpressure.rb | Implements server-supplied base backoff (baseBackoffMS) and updates exponential formula. |
| lib/mongo/retryable.rb | Passes the error into overload backoff computation for generic overload retry helper. |
| lib/mongo/operation/result.rb | Adds base_backoff_ms accessor to expose baseBackoffMS from server error replies. |
| lib/mongo/client.rb | Centralizes retry policy construction and rebuilds policy on Client#with when maxAdaptiveRetries changes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+81
to
+83
| # Step 3.6: the sum of the two backoffs is 0.3 seconds. The | ||
| # 0.6-second window accounts for variance between the two runs. | ||
| expect((with_backoff - (no_backoff + 0.6)).abs).to be < 0.6 |
Comment on lines
7
to
10
| it 'includes backpressure: true' do | ||
| metadata = described_class.new | ||
| expect(metadata.client_document[:backpressure]).to be true | ||
| expect(metadata.client_document[:backpressure]).to be '2' | ||
| end |
jamis
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the
baseBackoffMSpart of the client backpressure spec.backpressurefield fromtrueto"2"to signal support for server-driven backoff.baseBackoffMSfrom the server's overload error response and uses it as the base of the exponential backoff, falling back to the driver default when absent or non-positive.jitter * min(MAX_BACKOFF, base * 2**attempt), matching the spec. The same off-by-one is fixed inwith_transactionbackoff.Client#withso a derived client picks up a changedmax_adaptive_retries.Updates unit and prose tests accordingly.
RUBY-3901